
makers <- xgene
library(multiMiR)
#mRNA-miRNA
gene2mir <- get_multimir(
  org = "hsa",
  target = makers,
  table = "validated",
  summary = TRUE,
  predicted.cutoff = 10,
  predicted.cutoff.type = "p"
)

miRNA <- gene2mir@summary %>%
  dplyr::select(mature_mirna_id, target_symbol) %>% 
  distinct()

# dim(miRNA)
names(gene2mir@summary)
# view(gene2mir@summary)
# miRNA-lncRNA
lncRNA <- data.table::fread("/data/Separated_Users/wangcy/project/P04_F220809002_osteoporosis/data/starBaseV3_hg19_CLIP-seq_lncRNA_all.txt")

load("/data/Separated_Users/wangcy/project/P04_F220809002_osteoporosis/data/anno.Rdata",verbose = T)


lncRNA <- lncRNA %>% dplyr::filter(
  # clipExpNum > 4,
  miRNAname %in% miRNA$mature_mirna_id,
  geneID %in% str_remove(lnc_anno$gene_id, "\\.\\d"),
  degraExpNum > 0, 
  geneType == 'lincRNA'
) %>% dplyr::select(miRNAname, geneName) %>% distinct()

names(lncRNA) <- c("source", "target")
names(miRNA) <- c("source", "target")

# mRNA to TF
trust <- read.delim("/data/Separated_Users/wangcy/project/P04_F220809002_osteoporosis/data/trrust_rawdata.human.tsv")
tf <- trust %>% dplyr::filter(TF %in% makers | target %in% makers) %>% 
  dplyr::select(TF,target) %>% 
  dplyr::rename(source=TF)

# to cytoscape
net <- rbind(miRNA, lncRNA,tf)
property <- tibble(
  nodes = c(
    miRNA$source,
    lncRNA$source,
    miRNA$target,
    lncRNA$target,
    tf$source,
    tf$target
  ),
  type = rep(c("miRNA", "mRNA", "lncRNA","Transcription Factor","mRNA"),
    times = c(
      nrow(miRNA) + nrow(lncRNA),
      nrow(miRNA),
      nrow(lncRNA),
      nrow(tf),
      nrow(tf)
    )
  )
)
property = distinct(property,nodes,.keep_all = T)

write_tsv2(net,'out/1.sc/6.neutrophil/06.cls/6、蛋白相互作用网络分析/NET.tsv')
write_tsv2(property,'out/1.sc/6.neutrophil/06.cls/6、蛋白相互作用网络分析/property.tsv')
